package com.itheima.circleprogressbutton;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final CircleProgressView circleprogressview = (CircleProgressView) findViewById(R.id.circleprogressview);
		circleprogressview.setNote("gaga");
		circleprogressview.setIcon(R.drawable.ic_pause);

		circleprogressview.setProgressEnable(true);
		circleprogressview.setMax(360);

		circleprogressview.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				new AsyncTask<Void, Integer, Void>() {
					int	i	= 0;

					@Override
					protected Void doInBackground(Void... params) {
						while (true) {
							SystemClock.sleep(1000);
							publishProgress(i);
							if (i >= 360) {
								break;
							}
							i++;
						}
						return null;
					}

					protected void onProgressUpdate(Integer[] values) {
						int i = values[0];
						circleprogressview.setProgress(i);
						circleprogressview.setNote(i+"%");
					};
				}.execute();
			}
		});
		// circleprogressview.setBackground(new ColorDrawable(Color.TRANSPARENT));
	}
}
